package chapter04;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
@SuppressWarnings("all")
public class poll {
   
    public static void main(String[] args) {
        int[][] points={{10,16},{2,8},{1,6},{7,12}};
        
        System.out.println(poll_sort(points));
        
        
    }
    public static  int poll_sort(int[][] points) {
        if(points == null ) {
            return 0;
        }
        Arrays.sort(points, (a, b) -> (a[1] - b[1]));
//        Arrays.sort(points,new Comparator<int[]>(){
//            public int compare(int[] point1,int[] point2){
//                if(point1[1]>point2[1]){
//                    return 1;
//                }else if (point1[1]<point2[1]) {
//                    return -1;
//                }else {
//                    return 0;
//                }
//            }
//        });
        
        int poll_1=points[0][1];
        int count=1;
        
        for (int i = 0; i < points.length; i++) {
            if(poll_1<points[i][0]) {
                poll_1=points[i][1];
                count++;
            }
        }
        return count;
    }

}

